package demo.codeanalyzer.processor;

public class ObjectPropertyTypeWriter implements PropertyTypeWriter {

	private final PropertyPrinter propertyPrinter;

	public ObjectPropertyTypeWriter(PropertyPrinter propertyPrinter) {
		this.propertyPrinter = propertyPrinter;
	}

	public void endPropertyDefinition(StringBuilder objectPropertyBuilder) {
		objectPropertyBuilder.append("</owl:ObjectProperty>\n\n");
	}

	public void startPropertyDefinition(StringBuilder objectPropertyBuilder) {
		objectPropertyBuilder.append(String.format(
				"<owl:ObjectProperty %s >\n", propertyPrinter.id()));
	}

	public void writeRangeDefinition(StringBuilder objectPropertyBuilder) {
		objectPropertyBuilder.append(String.format("<rdf:range %s />\n",
				propertyPrinter.resource(tokenize(propertyPrinter
						.rangeResource()))));
	}

	private String tokenize(String string) {
		if (string.indexOf(".") < 0)
			return string;
		int lastDot = string.lastIndexOf(".");
		return string.substring(lastDot + 1);
	}

	public void printLabel(StringBuilder objectPropertyBuilder, String label) {
		objectPropertyBuilder.append(String.format(
				"<rdfs:label>%s</rdfs:label>\n", label));
	}

}
